package servlet;

import bao.CartDao;
import model.Cart;
import service.CartService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class QueryCartByName_Servlet extends HttpServlet {
    public QueryCartByName_Servlet() {
        super();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置 请求和响应的 编码字符为"utf-8"
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String bk_name = req.getParameter("name");
        CartDao cartDao = new CartDao();
        List<Cart> carts = cartDao.QueryCartByName(bk_name);
        req.setAttribute("cart",carts);
        req.getRequestDispatcher("main/cartbyname.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
